<?php

namespace app\service;


use app\common\Esclient;

class ChatService extends Service
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取单条es聊天信息
     * @param $id 消息id
     * @param $room_id 房间号
     * @return array|mixed
     */
    static public function getChatInfoById($id, $room_id)
    {
        // es查询条件
        $options = [
            'index' => 'es_chat_history',
            'size'  => 1,
            'from'  => 0,
            'sort'  => ['create_time' => 'desc'],
            'where' => [
                ['id', '=', $id],
                ['room_id', '=', $room_id]
            ],
        ];

        // 获取数据
        $es_client = new Esclient();
        $response  = $es_client->search($options);

        return !empty($response['data']) ? $response['data'][0] : [];
    }

    /**
     * 获取屏蔽的消息
     * @param $room_id 房间号
     * @return array|mixed
     */
    static public function getChatShield($room_id)
    {
        // es查询条件
        $options = [
            'index' => 'es_chat_history',
            'size'  => 1000,
            'from'  => 0,
            'sort'  => [],
            'where' => [
                ['room_id', '=', $room_id],
                ['status', '=', 0]
            ],
        ];

        // 获取数据
        $es_client = new Esclient();
        $response  = $es_client->search($options);

        return !empty($response['data']) ? $response['data'] : [];
    }


}